
#include "sys_msg.h"
#include "mcntl_cjson.h"
#include "lvgl.h"
#include <time.h>

static sys_msg_manage_t  msg_info;
static mcntl_cjson* msg_root  = NULL;
static mcntl_cjson* msg_array = NULL;

int msg_info_init(void)
{
    msg_info.len = 0;

    msg_info.e_head = (slist_t *)malloc(sizeof(slist_t));
	if (msg_info.e_head == NULL) {
		l_d("e_head null\n");
		return -1;
	}

    slist_init(msg_info.e_head);

    return 0;
}

int msg_info_destroy(void)
{
	if(!msg_info.e_head){
		return -1;
	}

    return 0;
}

int msg_info_add(msg_info_t *msg)
{
    int title_len = 0;
    int txt_len   = 0;
    sys_msg_t * obj = NULL;

	if(!msg_info.e_head){
		return -1;
	}

    obj = (sys_msg_t *)malloc(sizeof(sys_msg_t));
    if(obj == NULL){
        l_d("obj err\n");
        return -1;
    }
    memset(obj, 0, sizeof(sys_msg_t));
    slist_init(&(obj->e_tail));
    //**************************************************
    obj->e_attr.t_id    = msg->t_id;
    obj->e_attr.t_year  = msg->t_year;
    obj->e_attr.t_month = msg->t_month;
    obj->e_attr.t_day   = msg->t_day;

    obj->e_attr.t_hour  = msg->t_hour;
    obj->e_attr.t_min   = msg->t_min;
    obj->e_attr.t_sec   = msg->t_sec;
    obj->e_attr.is_read = msg->is_read;
    //**************************************************
    title_len = strlen(msg->title) + 1;

    obj->e_attr.title    = (char *)malloc(title_len);
    if(obj->e_attr.title == NULL){
        l_d("title buff err\n");
        free(obj);
        obj = NULL;
        return -1;
    }

    memset(obj->e_attr.title, 0, title_len);
    snprintf(obj->e_attr.title,title_len,"%s",msg->title);
    //**************************************************
    txt_len = strlen(msg->buff) + 1;

    obj->e_attr.buff    = (char *)malloc(txt_len);
    if(obj->e_attr.buff == NULL){
        l_d("buff err\n");
        free(obj);
        obj = NULL;
        return -1;
    }

    memset(obj->e_attr.buff, 0, txt_len);
    snprintf(obj->e_attr.buff,txt_len,"%s",msg->buff);
    //**************************************************
    msg_info.len++;
    slist_add_tail(msg_info.e_head,&(obj->e_tail));
    //**************************************************

    // debug_d("title=%s\n",msg->title);
    // debug_d("buff=%s\n",msg->buff);

    // debug_d("objtitle=%s\n",obj->e_attr.title);
    // debug_d("objbuff=%s\n",obj->e_attr.buff);

    return 0;
}


int msg_info_del(int msg_id)
{
	int ret = 0;

	slist_t* node;
	sys_msg_t * obj = NULL;

	if(!msg_info.e_head){
		return -1;
	}
	if(slist_isempty(msg_info.e_head)){
		l_d("list empty.\n");
		return -1;
	}

    l_d("len=%d\n",msg_info.len);

	slist_for_each(node, (msg_info.e_head))
	{
		obj = slist_entry(node, sys_msg_t, e_tail);
		if(obj){
            if(obj->e_attr.t_id  != msg_id){
                continue;
            }
            ret = 1;
            break;
		}
	}

	if(ret){
		slist_remove(msg_info.e_head, &(obj->e_tail));
		msg_info.len--;

        if(obj){
            if(obj->e_attr.buff){
                free(obj->e_attr.buff);
                obj->e_attr.buff = NULL;
            }
            if(obj->e_attr.title){
                free(obj->e_attr.title);
                obj->e_attr.title = NULL;
            }

            free(obj);
            obj = NULL;
        }
	}

	return 0;
}

int msg_info_trav(void)
{
	slist_t* node;
    sys_msg_t * obj = NULL;

	if(!msg_info.e_head){
		return -1;
	}

	if(slist_isempty(msg_info.e_head)){
		l_d("list empty.\n");
		return -1;
	}

	slist_for_each(node,(msg_info.e_head))
	{
		obj = slist_entry(node,sys_msg_t,e_tail);
		if(obj){
			#if 1
			l_d("ymd=%d:%d:%d:%s\n",obj->e_attr.t_year,obj->e_attr.t_month,obj->e_attr.t_day,obj->e_attr.buff);
			#endif
		}
	}

	return 0;
}

int msg_info_get_len(void)
{
    return msg_info.len;
}

int msg_info_get_noread(void)
{
    int len = 0;
	slist_t* node;
    sys_msg_t * obj = NULL;

	if(!msg_info.e_head){
		return len;
	}
	if(slist_isempty(msg_info.e_head)){
		l_d("list empty.\n");
		return len;
	}
	slist_for_each(node,(msg_info.e_head))
	{
		obj = slist_entry(node,sys_msg_t,e_tail);
		if(obj)
        {
            if(!obj->e_attr.is_read)
            {
                len ++;
            }
		}
	}

    return len ;
}

int msg_info_clear_all_noread(void)
{
	slist_t* node  = NULL;
    sys_msg_t* obj = NULL;

	if(!msg_info.e_head){
		return 0;
	}
	if(slist_isempty(msg_info.e_head)){
		l_d("list empty.\n");
		return 0;
	}
	slist_for_each(node,(msg_info.e_head))
	{
		obj = slist_entry(node,sys_msg_t,e_tail);
		if(obj)
        {
            if(!obj->e_attr.is_read)
            {
                obj->e_attr.is_read = 1;
            }
		}
	}
    return 0 ;
}

sys_msg_t * msg_info_get_by_index(int index)
{
    int len = 0;
	slist_t* node;
    sys_msg_t * obj = NULL;

	if(!msg_info.e_head){
		return -1;
	}
	if(slist_isempty(msg_info.e_head)){
		l_d("list empty.\n");
		return NULL;
	}
	slist_for_each(node,(msg_info.e_head))
	{
		obj = slist_entry(node,sys_msg_t,e_tail);
		if(obj)
        {
            if(len == index)
            {
                #if 0
                l_d("find index=%d:%s\n",index,obj->e_attr.buff);
                #endif
                return obj;
            }
            len++;
		}
	}

	return NULL;
}

int system_message_add(char* title,char* detail)
{
    int len = 0;
    unsigned int num = 0;
    msg_info_t sysmsg;

    if((!title)||(!detail)){
        return -1;
    }

    memset(&sysmsg,0,sizeof(msg_info_t));

    num += pt_year_get();
    num += pt_month_get();
    num += pt_day_get();
    num += pt_hour_get();
    num += pt_minute_get();
    num += pt_sec_get();
    num += lv_rand(1,100000000);

    debug_d("num=%d\n",num);

    sysmsg.t_id    = num;
    sysmsg.t_year  = pt_year_get();
    sysmsg.t_month = pt_month_get();
    sysmsg.t_day   = pt_day_get();

    sysmsg.t_hour  = pt_hour_get();
    sysmsg.t_min   = pt_minute_get();
    sysmsg.t_sec   = pt_sec_get();
    sysmsg.is_read = 0;

    sysmsg.title   = title;
    sysmsg.buff    = detail;
    
    msg_info_add(&sysmsg);

    int ret = -1;
    char* msg_str = NULL;
    ret = sys_message_add_info(&sysmsg);
    if(!ret){
        sys_message_remove_timeout_msg();
        sys_message_debug();
        msg_str = sys_message_dump();
        if(msg_str){
            sys_message_clear();
            sys_message_info_save(msg_str);
            mcntl_cjson_free(msg_str);
        }
    }

    return 0;
}

int sys_message_write_info(void)
{
    char* msg_str = NULL;
    sys_message_debug();
    msg_str = sys_message_dump();
    if(msg_str){
        sys_message_clear();
        sys_message_info_save(msg_str);
        mcntl_cjson_free(msg_str);
    }

    return 0;
}

#if 0
#define MSG_TEMP_PATH    ("/mnt/lfs/sys_message.tmp")
#define MSG_PATH         ("/mnt/lfs/sys_message.ini")
#else
#define MSG_TEMP_PATH    ("./sys_message.tmp")
#define MSG_PATH         ("./sys_message.ini")
#endif

int sys_message_clear(void)
{
    int fd = -1;
    fd = open(MSG_PATH,O_WRONLY|O_CREAT,0666);
    if(fd < 0){
        return -1;
    }
    close(fd);
    fd = -1;

    debug_d("sys message clear\n");

    return 0;
}
int sys_message_info_save(const char* context)
{
    int ret = -1;
    int fp = -1;
    if(!context){
        return 0;
    }
    debug_i("sysmsg info save\n");
    for (int i = 0; i < 3; i++) {
        fp = open(MSG_TEMP_PATH,O_WRONLY|O_CREAT,0666);
        if (fp > 0) {
            ret = write(fp,context,strlen(context));
            fsync(fp);
            close(fp);
            fp = -1;
            rename(MSG_TEMP_PATH, MSG_PATH); 
            unlink(MSG_TEMP_PATH);
            
            debug_d("sysmsg write success:%d:%s\n",ret,MSG_PATH);
            return 0;
        }
        //ms_osal_thread_sleep(1000);
    }   

    return 0;
}

int sys_message_file_is_exist(void)
{
    int fp = -1;

    fp = open(MSG_PATH,O_RDONLY,0666);
    if(fp<0){
        debug_e("file no exit %s\n",MSG_PATH);
        return -1;
    }
    close(fp);
    fp = -1;

    return 0;
}

int sys_message_info_read(void)
{
    int ret = -1;
    int fp = -1;
    char* buf = NULL;
    unsigned int len = 0;

	long int size = 0;
	struct stat fileinfo;

    ret = sys_message_file_is_exist();
    if(ret != 0){
        return -1;
    }

	ret = stat(MSG_PATH,&fileinfo);
	if(ret == -1){
		debug_e("device file size err:%s\n",MSG_PATH);
		return 0;
	}else{
		size = (long int )fileinfo.st_size;
        debug_d("size=%ld\n",size);
	}

    if(!size){
        return 0;
    }

    buf = (char*)psram_malloc(size);
    if(!buf){
        return 0;
    }

    ret = 0;
    for (int i = 0; i < 3; i++) {
        fp = open(MSG_PATH,O_RDONLY,0666);
        if (fp > 0) {
            len = read(fp,buf,size);
            close(fp);
            fp = -1;
            ret = 1;
            debug_d("read device success len=%ld:%s\n",len,buf);
            break;
        }
        // sleep(1);
        // ms_osal_thread_sleep(1000);
    }
    if(ret){
        int flag = 0;
        sys_message_create(buf,len);
        flag = sys_message_remove_timeout_msg();
        if(!flag){
            sys_message_write_info(); 
        }
        sys_message_add_to_list();
    }
    psram_free(buf);
    buf = NULL;

    return 0;
}

int sys_message_add_info(msg_info_t* sysmsg)
{
    mcntl_cjson* info = NULL;

    if((!msg_array)||(!sysmsg)){
        return -1;
    }
    info = mcntl_cjson_create_object();
    if(!info){
        return -1;
    }

    mcntl_cjson_add_number_to_object(info,"msgid",  sysmsg->t_id);
    mcntl_cjson_add_number_to_object(info,"year",   sysmsg->t_year);
    mcntl_cjson_add_number_to_object(info,"month",  sysmsg->t_month);
    mcntl_cjson_add_number_to_object(info,"day",    sysmsg->t_day);
    mcntl_cjson_add_number_to_object(info,"hour",   sysmsg->t_hour);
    mcntl_cjson_add_number_to_object(info,"minute", sysmsg->t_min);
    mcntl_cjson_add_number_to_object(info,"sec",    sysmsg->t_sec);
    mcntl_cjson_add_number_to_object(info,"is_read",sysmsg->is_read);

    mcntl_cjson_add_string_to_object(info,"title",  sysmsg->title);
    mcntl_cjson_add_string_to_object(info,"detail", sysmsg->buff);

    mcntl_cjson_add_item_to_array(msg_array,info);

    return 0;
}

//7天内 20条
int sys_message_del_info(msg_info_t* msg)
{
    int i = 0;
    int find_flag = 0;
    int total_num = 0 ;
    int t_year  = 0;
    int t_month = 0;
    int t_day   = 0;
    int t_hour  = 0;
    int t_min   = 0;
    int t_sec   = 0;
    unsigned int t_id = 0;
    if((!msg_array)||(msg)){
        return -1;
    }
    total_num = mcntl_cjson_get_array_num(msg_array);
    debug_d("total_num=%d\n",total_num);
    for(i=0;i<total_num;i++)
    {
        mcntl_cjson* info = NULL;
        info = mcntl_cjson_get_array_item(msg_array,i);
        if(!info){
            continue;
        }
        mcntl_cjson* c_year  = NULL;
        mcntl_cjson* c_month = NULL;
        mcntl_cjson* c_day   = NULL;
        mcntl_cjson* c_hour  = NULL;
        mcntl_cjson* c_min   = NULL;
        mcntl_cjson* c_sec   = NULL;
        mcntl_cjson* c_id    = NULL;
        c_year  = mcntl_cjson_get_object_item(info,"year");
        c_month = mcntl_cjson_get_object_item(info,"month");
        c_day   = mcntl_cjson_get_object_item(info,"day");
        c_hour  = mcntl_cjson_get_object_item(info,"hour");
        c_min   = mcntl_cjson_get_object_item(info,"minute");
        c_sec   = mcntl_cjson_get_object_item(info,"sec");
        c_id    = mcntl_cjson_get_object_item(info,"msgid");
        if((!c_year)||(!c_month)||(!c_day)||(!c_hour)||(!c_min)||(!c_sec)){
            continue;
        }
        if(!c_id){
            continue;
        }
        t_year  = mcntl_cjson_get_number_value(c_year);
        t_month = mcntl_cjson_get_number_value(c_month);
        t_day   = mcntl_cjson_get_number_value(c_day);
        t_hour  = mcntl_cjson_get_number_value(c_hour);
        t_min   = mcntl_cjson_get_number_value(c_min);
        t_sec   = mcntl_cjson_get_number_value(c_sec);
        t_id    = mcntl_cjson_get_number_value(c_id);
        if(t_year != msg->t_year){
            continue;
        }
        if(t_month != msg->t_month){
            continue;
        }
        if(t_day != msg->t_day){
            continue;
        }
        if(t_hour != msg->t_hour){
            continue;
        }
        if(t_min != msg->t_min){
            continue;
        }
        if(t_sec != msg->t_sec){
            continue;
        }
        if(t_id != msg->t_id){
            continue;
        }
        find_flag = 1;
        break;
    }
    if(find_flag)
    {
        debug_d("find-i:time=%d:%d/%d/%d-%d:%d:%d\n",i,t_year,t_month,t_day,t_hour,t_min,t_sec);
        mcntl_cjson_DeleteItemFromArray(msg_array,i);
    }

    return 0;
}
//7天内 20条
int sys_message_remove_timeout_msg(void)
{
    int i = 0;
    int remove_flag = -1;
    int total_num = 0;
    int total_num_bak = 0;

    int t_year  = 0;
    int t_month = 0;
    int t_day   = 0;
    int t_hour  = 0;
    int t_min   = 0;
    int t_sec   = 0;

    struct tm cur_time = {0};

    cur_time.tm_year = pt_year_get();
    cur_time.tm_mon  = pt_month_get();
    cur_time.tm_mday = pt_day_get();
    cur_time.tm_hour = pt_hour_get();
    cur_time.tm_min  = pt_minute_get();
    cur_time.tm_sec  = pt_sec_get();

    unsigned int cur_time_now  = mktime(&cur_time);

    debug_d("cur_time_now=%d\n",cur_time_now);

    if(!msg_array){
        return -1;
    }
    total_num = mcntl_cjson_get_array_num(msg_array);
    total_num_bak = total_num;
    debug_d("total_num=%d\n",total_num);
    i=0;
    while(i<total_num)
    {
        mcntl_cjson* info = NULL;
        info = mcntl_cjson_get_array_item(msg_array,i);
        if(!info){
            debug_d("err0\n");
            break;
        }
        mcntl_cjson* c_year  = NULL;
        mcntl_cjson* c_month = NULL;
        mcntl_cjson* c_day   = NULL;
        mcntl_cjson* c_hour  = NULL;
        mcntl_cjson* c_min   = NULL;
        mcntl_cjson* c_sec   = NULL;
        c_year  = mcntl_cjson_get_object_item(info,"year");
        c_month = mcntl_cjson_get_object_item(info,"month");
        c_day   = mcntl_cjson_get_object_item(info,"day");
        c_hour  = mcntl_cjson_get_object_item(info,"hour");
        c_min   = mcntl_cjson_get_object_item(info,"minute");
        c_sec   = mcntl_cjson_get_object_item(info,"sec");
        if((!c_year)||(!c_month)||(!c_day)||(!c_hour)||(!c_min)||(!c_sec)){
            debug_d("err1\n");
            break;
        }
        t_year  = mcntl_cjson_get_number_value(c_year);
        t_month = mcntl_cjson_get_number_value(c_month);
        t_day   = mcntl_cjson_get_number_value(c_day);
        t_hour  = mcntl_cjson_get_number_value(c_hour);
        t_min   = mcntl_cjson_get_number_value(c_min);
        t_sec   = mcntl_cjson_get_number_value(c_sec);

        struct tm temp = {0};

        debug_d("t_year=%d\n",t_year);

        temp.tm_year = t_year;
        temp.tm_mon  = t_month;
        temp.tm_mday = t_day;
        temp.tm_hour = t_hour;
        temp.tm_min  = t_min;
        temp.tm_sec  = t_sec;
    
        unsigned int temp_time  = mktime(&temp) + 7*24*60*60;

        debug_d("temp_time=%d:%d\n",i,temp_time);

        if(cur_time_now > temp_time)
        {
            debug_d("remove msg %d\n",i);
            total_num_bak--;
            mcntl_cjson_DeleteItemFromArray(msg_array,i);
            remove_flag = 0;
            i=0;
        }
        else{
            if(total_num_bak > 20)
            {
                debug_d("remove msg %d\n",i);
                total_num_bak--;   
                mcntl_cjson_DeleteItemFromArray(msg_array,i);   
                remove_flag = 0;  
                i=0;                    
            }
            else{
                i++;
            }
        }          
    }

    debug_d("remove msg finish\n");

    return remove_flag;
}

int sys_message_add_to_list(void)
{
    int i = 0;
    int find_flag = 0;
    int total_num = 0 ;
    int t_year  = 0;
    int t_month = 0;
    int t_day   = 0;
    int t_hour  = 0;
    int t_min   = 0;
    int t_sec   = 0;
    int t_read  = 0;
    unsigned int t_id = 0;
    char* t_title  = NULL;
    char* t_detail = NULL;
    if(!msg_array){
        return -1;
    }
    total_num = mcntl_cjson_get_array_num(msg_array);
    debug_d("total_num=%d\n",total_num);
    for(i=0;i<total_num;i++)
    {
        mcntl_cjson* info = NULL;
        info = mcntl_cjson_get_array_item(msg_array,i);
        if(!info){
            continue;
        }
        mcntl_cjson* c_year  = NULL;
        mcntl_cjson* c_month = NULL;
        mcntl_cjson* c_day   = NULL;
        mcntl_cjson* c_hour  = NULL;
        mcntl_cjson* c_min   = NULL;
        mcntl_cjson* c_sec   = NULL;
        mcntl_cjson* c_read    = NULL;
        mcntl_cjson* c_title   = NULL;
        mcntl_cjson* c_detail  = NULL;
        mcntl_cjson* c_id      = NULL;
        c_id    = mcntl_cjson_get_object_item(info,"msgid");
        c_year  = mcntl_cjson_get_object_item(info,"year");
        c_month = mcntl_cjson_get_object_item(info,"month");
        c_day   = mcntl_cjson_get_object_item(info,"day");
        c_hour  = mcntl_cjson_get_object_item(info,"hour");
        c_min   = mcntl_cjson_get_object_item(info,"minute");
        c_sec   = mcntl_cjson_get_object_item(info,"sec");

        c_read    = mcntl_cjson_get_object_item(info,"is_read");
        c_title   = mcntl_cjson_get_object_item(info,"title");
        c_detail  = mcntl_cjson_get_object_item(info,"detail");

        if((!c_year)||(!c_month)||(!c_day)||(!c_hour)||(!c_min)||(!c_sec)){
            continue;
        }
        if((!c_read)||(!c_title)||(!c_detail)){
            continue;
        }
        if(!c_id){
            continue;
        }

        t_id     = mcntl_cjson_get_number_value(c_id);
        t_year   = mcntl_cjson_get_number_value(c_year);
        t_month  = mcntl_cjson_get_number_value(c_month);
        t_day    = mcntl_cjson_get_number_value(c_day);
        t_hour   = mcntl_cjson_get_number_value(c_hour);
        t_min    = mcntl_cjson_get_number_value(c_min);
        t_sec    = mcntl_cjson_get_number_value(c_sec);
        t_read   = mcntl_cjson_get_number_value(c_read);
        t_title  = mcntl_cjson_get_string_value(c_title);
        t_detail = mcntl_cjson_get_string_value(c_detail);

        msg_info_t msg;
        memset(&msg,0,sizeof(msg_info_t));

        msg.t_id     = t_id;
        msg.t_year   = t_year;
        msg.t_month  = t_month;
        msg.t_day    = t_day;
        msg.t_hour   = t_hour;
        msg.t_min    = t_min;
        msg.t_sec    = t_sec;
        msg.is_read  = t_read;
        msg.title    = t_title;
        msg.buff     = t_detail;
        int ret = msg_info_add(&msg);
        if(ret != 0){
            debug_e("add err\n");
        }else{
            debug_d("add succeed\n");
        } 
    }

    return 0;
}

int sys_message_update_read_flag(int t_msgid,int read_flag)
{
    int i = 0;
    int find_flag = 0;
    int total_num = 0 ;
    unsigned int t_id  = 0;
    if(!msg_array){
        return -1;
    }
    total_num = mcntl_cjson_get_array_num(msg_array);
    debug_d("total_num=%d\n",total_num);
    for(i=0;i<total_num;i++)
    {
        mcntl_cjson* info = NULL;
        info = mcntl_cjson_get_array_item(msg_array,i);
        if(!info){
            continue;
        }
        mcntl_cjson* c_id  = NULL;
        c_id  = mcntl_cjson_get_object_item(info,"msgid");
        if(!c_id){
            continue;
        }
        t_id  = mcntl_cjson_get_number_value(c_id);
        if(t_id != t_msgid){
            continue;
        }
        debug_d("update this info\n");
        mcntl_cjson_ReplaceItemInObjectCaseSensitive(info,"is_read",cJSON_CreateNumber(read_flag));    
    
        break;
    }

    return 0;
}

int sys_message_clear_read_flag(void)
{
    int i = 0;
    int total_num = 0 ;
    if(!msg_array){
        return -1;
    }
    total_num = mcntl_cjson_get_array_num(msg_array);
    debug_d("total_num=%d\n",total_num);
    for(i=0;i<total_num;i++)
    {
        mcntl_cjson* info = NULL;
        info = mcntl_cjson_get_array_item(msg_array,i);
        if(!info){
            continue;
        }
        int read_flag = 1;
        debug_d("update this info\n");
        mcntl_cjson_ReplaceItemInObjectCaseSensitive(info,"is_read",cJSON_CreateNumber(read_flag));
    }

    return 0;
}

int sys_message_create(char* buff,int len)
{
    if(buff != NULL)
    {
        msg_root = mcntl_cjson_parse(buff,len);
        if(!msg_root){
            return -1;
        }
        msg_array = mcntl_cjson_get_object_item(msg_root,"msginfo");
        if(!msg_array){
            return -1;
        }
    }
    else
    {
        msg_root = mcntl_cjson_create_object();
        if(!msg_root){
            return -1;
        }
        msg_array = mcntl_cjson_create_array();
        if(!msg_array){
            mcntl_cjson_delete(msg_array);
            return -1;
        }
    
        mcntl_cjson_add_item_to_object(msg_root,"msginfo",msg_array);
    }

    return 0;
}

char* sys_message_dump(void)
{
    char* msg_str = NULL;
    if(!msg_root){
        return NULL;
    }
    msg_str = mcntl_cjson_print(msg_root);
    return msg_str;
}

int sys_message_debug(void)
{
    char* msg_str = NULL;
    if(!msg_root){
        return -1;
    }
    msg_str = mcntl_cjson_print(msg_root);
    debug_d("msg_str=%s\n",msg_str);
    mcntl_cjson_free(msg_str);

    return 0;
}

int sys_message_file_init(void)
{
    int ret = -1;

    ret = sys_message_file_is_exist();
    if(ret != 0){
        //file not exist
        sys_message_create(NULL,0);
    }else{
        sys_message_info_read();
    }

    sys_message_debug();

    return 0;
}



